import { BattleReport, BattleAction } from '../../types/battle';
import { Effect, EffectType } from '../../types/effect';

export function displayBattleReport(report: BattleReport): void {
  console.log('\n=== 战斗报告 ===\n');
  
  // 显示每个回合的情况
  report.turns.forEach((turn, index) => {
    console.log(`\n第 ${index + 1} 回合:`);
    
    // 显示行动
    turn.actions.forEach(action => {
      displayAction(action);
    });

    // 显示效果
    if (turn.effects.length > 0) {
      console.log('\n触发效果:');
      turn.effects.forEach(effect => displayEffect(effect as Effect));
    }
  });

  // 显示战斗结果
  console.log('\n=== 战斗结果 ===');
  console.log(`胜利方: ${report.winner ? report.winner.id : '平局'}`);
  
  // 显示最终状态
  console.log('\n最终兵力:');
  report.finalState.remainingTroops.forEach((troops, generalId) => {
    console.log(`${generalId}: ${troops}`);
  });

  // 显示伤害统计
  console.log('\n伤害统计:');
  report.finalState.totalDamage.forEach((damage, generalId) => {
    console.log(`${generalId} 造成伤害: ${damage}`);
  });
}

function displayAction(action: BattleAction): void {
  const targetDesc = Array.isArray(action.target) 
    ? action.target.map(t => t.name).join(',')
    : action.target.name;

  console.log(
    `${action.actor.name} ${
      action.type === 'skill' ? `使用技能 ${action.skillId}` : '进行普通攻击'
    } 对 ${targetDesc} 造成 ${action.damage} 点伤害${
      action.healing ? ` 并恢复 ${action.healing} 点兵力` : ''
    }`
  );
}

function displayEffect(effect: Effect): void {
  console.log(
    `${effect.source || 'Unknown'} 触发效果: ${effect.type} (数值:${effect.value}, 持续:${effect.duration}回合)`
  );
}
